#pragma once

#include <iostream>
using namespace std;


char* strcat(char *str1, char *str2) {

	int length1 = 0, length2 = 0;

	/*if (str1 == NULL && str2 == NULL)
	{
		return NULL;
	}
	*/
	if (str1 != NULL) 
	{
		while (str1[length1] != '\0')
		{
			length1++;
		}
	}
	else
	{
		length1 = 0;
	}

	if (str2 != NULL) 
	{
		while (str2[length2] != '\0')
		{
			length2++;
		}
	}
	else
	{
		length2 = 0;
	}

	char *dest = (char*)malloc(length1 + length2 + 1);

	int s1 = 0, s2 = 0, i = 0;

	if (length1 == 0)
	{
		if (length2 != 0)
		{
			while (str2[s2] != '\0')
			{
				dest[i++] = str2[s2];
				s2++;
			}
		}
	}
	else
	{
		while (str1[s1] != '\0')
		{
			dest[i++] = str1[s1];
			s1++;
		}

		if (length2 != 0)
		{
			while (str2[s2] != '\0')
			{
				dest[i++] = str2[s2];
				s2++;
			}
		}
	}

	dest[length1 + length2] = '\0';

	return dest;

}
/*int main(int argc, _TCHAR* argv[])
{
	char str1[20],str2[30];
	int length = 20;
	printf("input str1:\n");
	gets(str1);
	printf("input str2:\n");
	gets(str2);
	puts(str1);
    
	return 0;
}*/
